package com.domi;

import com.alibaba.fastjson2.JSON;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.Data;
import org.springframework.cloud.gateway.route.RouteDefinition;
import org.yaml.snakeyaml.Yaml;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

public class T {

    static String configContent ="- id: provider1-router\n" +
            "  order: 1\n" +
            "  name: Path\n" +
            "  uri: lb://my-gateway-provider1\n" +
            "  predicates:\n" +
            "    - args:\n" +
            "        pattern: /hello/**\n" +
            "- id: provider2-router\n" +
            "  order: 2\n" +
            "  name: Path\n" +
            "  uri: lb://my-gateway-provider2\n" +
            "  predicates:\n" +
            "    - args:\n" +
            "        pattern: /welcome/**";

    public static void main(String[] args) throws Throwable {
//        List<RouteDefinition> routeDefinitions = JSON.parseArray(configContent, RouteDefinition.class);
//        ObjectMapper mapper = new ObjectMapper();
//        Map<String, Object> nacosDataMap = mapper.readValue(configContent,
//                LinkedHashMap.class);
//        System.out.println(nacosDataMap);
        Yaml yaml = new Yaml();
        List<RouteDefinition> routeDefinitions = yaml.load(configContent);
//        LinkedHashMap routeDefinitions = yaml.load(configContent);
        System.out.println(routeDefinitions);
    }

    @Data
    public static class RouteDefinitions {

        private List<RouteDefinition> routeDefinitions;

    }

}
